package demo01_basicGrammer

object Demo05_function_other {

  //传值参数，先计算，后带入
  def func_value(str:String) = {
    println("startValue")
    println(str)
    println("stopValue")
  }

  //传名参数，先带入，后计算
  def func_name(str: =>String) = {
    println("startName")
//    println(str)
    println("stopName")
  }

  //偏函数：是没有match的一组case语句 是 PartialFunction[A,B]类的一个实例
  def function_numTransform:PartialFunction[Int,String] = {
    case 1 => "壹"
    case 2 => "贰"
    case 3 => "叄"
    case 4 => "肆"
    case 5 => "伍"
    case _ => "other"
  }

  def function_rangeTransform()= {
    val list = (0 to 10).toList
    list.map{
      case x if x>=0 && x<=3 => "[0-3]"
      case x if x>3 && x<=6 => "[4-6]"
      case x if x>6 && x<=10 => "[7-10]"
      case _ => "other"
    }.foreach(println)

  }

  def main(args: Array[String]): Unit = {

//    func_name({
//      println("name")
//      "hello"
//    })

//    println(function_numTransform(1))
//    println(function_numTransform(2))
//    println(function_numTransform(3))
//    println(function_numTransform(4))
//    println(function_numTransform(5))
//    println(function_numTransform(6))


    function_rangeTransform
  }
}
